/*
 * Copyright (c)$today.year.month.day
 *  admin:郑程荣.
 *  文件名:ProjectListPresenter.java
 *  项目功能:
 */

/*
 * Copyright (c)$today.year.month.day
 *  admin:郑程荣.
 *  文件名:ProjectListPresenter.java
 *  项目功能:
 */

package com.jg.myproject.presenter;


import com.jg.myproject.api.BaseObserver;
import com.jg.myproject.api.RetrofitFactory;
import com.jg.myproject.api.RxSchedulers;
import com.jg.myproject.api.bean.BaseEntity;
import com.jg.myproject.api.bean.CommonRequestBean;
import com.jg.myproject.api.bean.reponse.CommonReponseBean;
import com.jg.myproject.module.base.IBasePresenter;
import com.jg.myproject.pview.IProjectListView;
import com.vondear.rxtools.view.RxToast;


import io.reactivex.Observable;


public class ProjectListPresenter implements IBasePresenter<CommonRequestBean> {
    private IProjectListView mIProjectListView;
    public ProjectListPresenter(IProjectListView projectListView){
        this.mIProjectListView = projectListView;
    }

    @Override
    public void getData(CommonRequestBean commonRequestBean) {
        Observable<BaseEntity<CommonReponseBean>> observable = RetrofitFactory.getInstance().getProjectList(commonRequestBean);
        observable.compose(RxSchedulers.<BaseEntity<CommonReponseBean>>compose(
                mIProjectListView.<BaseEntity<CommonReponseBean>>bindToLife())).subscribe(new BaseObserver<CommonReponseBean>(mIProjectListView) {
            @Override
            protected void onHandleSuccess(BaseEntity<CommonReponseBean> bean) {
                mIProjectListView.getReponseBeans(bean);
            }
            @Override
            protected void onHandleError(BaseEntity<CommonReponseBean> t) {
                RxToast.showToast(t.getDescription());

            }
        });
    }
}
